package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.StudentDao;
import com.itheima.edu.info.manager.domain.Student;

public class StudentService {
    private  StudentDao studentdao = new StudentDao();
    public  boolean addStudent(Student stu) {
        //导包

        //将学生对象传递给StudentDao
        return studentdao.addStudent(stu);
    }

    public   boolean affirm(String id) {
        Student[] studs = studentdao.find();
        for (int i = 0; i < studs.length; i++) {
            //防止空指针异常
            if (studs[i] != null && studs[i].getID().equals(id)) {
                return true;
            }
        }
        return false;
    }


    public  Student[] findAll() {
        Student[] studs = studentdao.find();
        for (int i = 0; i < studs.length; i++) {
            if (studs[i]!=null){
                return studs;
            }
        }
         return null;
    }

    public boolean removeStudent(String id) {
        boolean stu=studentdao.remove(id);
        if (stu){
            return true;
        }else {
            return false;
        }
    }

    public boolean change(String id, String name, String age, String birth) {
        boolean stu=studentdao.change(id,name,age,birth);
        if (stu){
            return true;
        }else {
            return false;
        }
    }
}
